package com.chain.BrotherExchange.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.chain.BrotherExchange.R;

import java.util.List;

public class SelectorListAdapter extends RecyclerView.Adapter<SelectorListAdapter.ViewHolder> {

    private final List<String> mListBeans;
    private final AdapterView.OnItemClickListener mOnItemClickListener;

    public SelectorListAdapter(List<String> listBeans, ListView.OnItemClickListener listener) {
        this.mListBeans = listBeans;
        this.mOnItemClickListener = listener;
    }

    @NonNull
    @Override
    public SelectorListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
        return new ViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_simple_list, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull SelectorListAdapter.ViewHolder holder, int position) {
        holder.mTextView.setText(mListBeans.get(position));
        holder.itemView.setOnClickListener(v ->
                mOnItemClickListener.onItemClick(null, v, position, 0)
        );
    }

    @Override
    public int getItemCount() {
        return mListBeans.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView mTextView;

        ViewHolder(@NonNull View itemView) {
            super(itemView);
            mTextView = itemView.findViewById(R.id.text_view);
        }
    }
}
